<template>
	<el-container>
		<el-aside>
		</el-aside>
		<el-container>
			<el-header style="font-size: 20px;font-weight: 600;text-align: center;display: block">系统维护...</el-header>
			<el-main className="nopadding">
				<el-alert class="page-msg" description="本模块为管理员操作模块,可以踢除用户并可开启维护功能！" type="warning" show-icon :closable="false"/>
				<el-card shadow="never" header="踢出用户">
					<el-main style="text-align: center">
						<el-form-item label="请指定一个用户后强制该用户下线">
						<select-user-dialog v-model:accountId="form.accountId" :mode="false"/>
						<el-button type="danger" @click="kickAccount" style="margin-left: 50px;display: inline-flex">踢出</el-button>
						</el-form-item>
					</el-main>
				</el-card>
				<el-card shadow="never" header="Redis清空">
					<div>
						当清空Redis缓存后，系统中所有登陆状态都会取消，用户需理新登陆。该功能主要用于账号登陆异常时使用。
					</div>
					<el-main style="text-align: center">
						<el-button type="danger" @click="clearSysRedis">清空redis缓存</el-button>
					</el-main>
				</el-card>
				<el-card shadow="never" header="系统维护">
					<div style="margin: 15px">
						<div v-if="status=='0'">
							<sc-status-indicator  pulse type="success"></sc-status-indicator><span style="font-size: 18px;margin-left: 20px;">运行中...</span>
						</div>
						<div v-if="status=='1'">
							<sc-status-indicator  pulse type="danger"></sc-status-indicator><span style="font-size: 18px;margin-left: 20px;">维护中...</span>
						</div>
					</div>
					<el-main>
						<el-form >
							<el-form-item label="提示语">
								<el-input type="textarea" v-model="form.info" placeholder="当系统处于维护状态时，该提示语将会在登陆时显示！"></el-input>
							</el-form-item>
							<div style="text-align: center;">
								<el-button type="danger" @click="setMainMode" :disabled="status=='1'">维护</el-button>
								<el-button type="success" @click="relieveMaintenanceMode" :disabled="status=='0'">启用</el-button>
							</div>

						</el-form>
					</el-main>
				</el-card>
			</el-main>
		</el-container>
		<el-aside>
		</el-aside>
	</el-container>
</template>

<script>
import SelectUserDialog from "@/views/module/selectUserDialog";

export default {
	name: 'layoutLCR',
	components: {SelectUserDialog},
	data() {
		return {
			form: {
				accountId: '',
				info:''
			},
			status:0,
		}
	},
	mounted() {
		this.getSysRunStatus();
	},
	methods: {
		async kickAccount() {
			var res = await this.$API.system.monitor.kickAccount.post({accountId:this.form.accountId});
			if (res.code == 200) {
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async clearSysRedis()
		{
			var res = await this.$API.system.monitor.clearSysRedis.post();
			if (res.code == 200) {
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async setMainMode()
		{
			var res = await this.$API.system.monitor.setMainMode.post({info:this.form.info});
			if (res.code == 200) {
				this.status='1';
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async relieveMaintenanceMode()
		{
			var res = await this.$API.system.monitor.relieveMaintenanceMode.post();
			if (res.code == 200) {
				this.status='0';
				this.$message.success("操作成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async getSysRunStatus(){
			var res = await this.$API.system.monitor.getSysRunStatus.get();
			if (res.code == 200) {
				this.status=res.data.status;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		}
	}
}
</script>

<style>
.title {
	font-weight: 600;
	font-size: 20px;
}
</style>
